package com.demo.logistics.stockControl.ui;

import java.util.ArrayList;

import com.demo.logistics.R;
import com.demo.logistics.entities.Products;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class ProductListArrayAdapter extends ArrayAdapter<Products> {
	private Activity context;
	private ArrayList<Products> prodObjList;
	
	public ProductListArrayAdapter(Activity context, ArrayList<Products> objects){
		super(context, R.layout.productlist_rowlayout, objects);
		this.context = context;
		this.prodObjList = objects;
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent){
		LayoutInflater inf = context.getLayoutInflater();
		View rowView = inf.inflate(R.layout.productlist_rowlayout, null, true);
		TextView tvId = (TextView)rowView.findViewById(R.id.tv_prod_id);
		TextView tvProdName = (TextView)rowView.findViewById(R.id.tv_prod_name);
		TextView tvBrand = (TextView)rowView.findViewById(R.id.tv_prod_brand);
		TextView tvPrice = (TextView)rowView.findViewById(R.id.tv_prod_price);
		Products tempProd = prodObjList.get(position);
		tvId.setText(((Integer)tempProd.getId()).toString());
		tvProdName.setText(tempProd.getName());
		tvBrand.setText(tempProd.getBrand());
		tvPrice.setText((((Double)tempProd.getPrice()).toString()));
		return rowView;
	}
}
